//
//  WlisUIBarButtonItem.swift
//  Swift_missScarlett
//
//  Created by xmg on 16/8/16.
//  Copyright © 2016年 wlis. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    /** 按钮高亮的图片 */
    class func itemWithCustomView(imageName : String,imageHight:String,target:AnyObject?,action :Selector)->UIBarButtonItem {
        
        let leftBtn = UIButton(type: .Custom);
        leftBtn.setImage(UIImage(named: imageName), forState: .Normal)
        leftBtn.setImage(UIImage(named: imageHight), forState: .Highlighted)
        leftBtn.sizeToFit()
        leftBtn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        let containView = UIView(frame: leftBtn.bounds)
        containView.addSubview(leftBtn)
        return UIBarButtonItem(customView: containView)
        
    }
    /** 选中状态的图片 */
    class func itemWithCustomView(imageName : String,imageSelected:String,target:AnyObject?,action :Selector)->UIBarButtonItem {
        
        let leftBtn = UIButton(type: .Custom);
        leftBtn.setImage(UIImage(named: imageName), forState: .Normal)
        leftBtn.setImage(UIImage(named: imageSelected), forState: .Selected)
        leftBtn.sizeToFit()
        leftBtn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        let containView = UIView(frame: leftBtn.bounds)
        containView.addSubview(leftBtn)
        return UIBarButtonItem(customView: containView)
        
    }
    /** 按钮设置 */
    class func backItemWithCustomView(imageName:String,imageHight:String,target:AnyObject?,action:Selector,title:String) ->UIBarButtonItem {
        let backBtn = UIButton(type: .Custom)
        backBtn.setTitle(title, forState: .Normal)
        backBtn.setTitleColor(UIColor.blackColor(), forState: .Normal)
        backBtn.setTitleColor(UIColor.redColor(), forState: .Highlighted)
        backBtn.setImage(UIImage(named: imageName), forState: .Normal)
        backBtn.setImage(UIImage(named: imageHight), forState: .Highlighted)
        backBtn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0)
        backBtn.sizeToFit()
        
        return UIBarButtonItem(customView: backBtn)
    }
    
}
